// 引入路由
const koaRouter = require('koa-router')
// 实例化路由
const router = new koaRouter()

// 自定义中间件
const ifyAdmin = require('../middleware/verifyAdmin')

const v = '/api/v1/admin'

// admin管理员
const User = require('../controllers/admin/user')
// 商品分类
const Cate = require('../controllers/admin/cate')
// 商品
const Goods = require('../controllers/admin/goods')


router
  .post(`${v}/user/add`, User.addAdmin)//添加管理员
  .post(`${v}/user/login`, User.loginAdmin)//管理员登录
  .post(`${v}/user/update`, User.updateAdmin)//修改管理员信息
  .get(`${v}/user/info`, ifyAdmin, User.getAdmin)//管理员信息
  .post(`${v}/user/logout`, ifyAdmin, User.logout)//管理员登出
  
  .get(`${v}/cates/list`,ifyAdmin, Cate.getCates)//获取分类
  .post(`${v}/cates/insert`, ifyAdmin, Cate.addCates)//添加分类
  
  .get(`${v}/goods/list`,ifyAdmin, Goods.listGoods)//获取商品
  .get(`${v}/goods/details`, ifyAdmin,Goods.getGoodsDetails)
  .post(`${v}/goods/insert`, ifyAdmin, Goods.addGoods)//添加商品
  .post(`${v}/goods/delete`, ifyAdmin,Goods.deleteGoods)
  .post(`${v}/goods/set/state`, ifyAdmin,Goods.setGoodsState)
  
  .post(`${v}/upload/img`,ifyAdmin,Goods.uploadImg)//上传商品图片
  .post(`${v}/delete/img`, ifyAdmin, Goods.deleteImg)//删除商品图片

module.exports = router